package com.aaa.service.impl;

import com.aaa.dao.MhallDao;
import com.aaa.entity.Mhall;
import com.aaa.entity.Product;
import com.aaa.service.MhallService;
import com.aaa.util.DefaultMsg;
import com.aaa.util.TableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MhallServiceImpl implements MhallService {
    @Autowired
    private MhallDao mhallDao;
    public TableData<Mhall> page(String keyword, Integer page, Integer limit) {
        TableData<Mhall> tableData=new TableData<Mhall>();
        Integer offset=(page-1)*limit;
        List<Mhall> data =  mhallDao.listPage(keyword,offset,limit);
        tableData.setData(data);
        Integer count=mhallDao.count(keyword);
        tableData.setCount(count);
        return tableData;
    }

    public DefaultMsg saveOrupdate(Mhall mhall) {
        DefaultMsg defaultMsg=new DefaultMsg();
        Integer count;
        if (mhall.getId()==null){
            count=mhallDao.save(mhall);
        }else{
            count=mhallDao.update(mhall);
        }
        if (count==0){
            defaultMsg.setSuccess(0);
            defaultMsg.setError("失败");
        }
        return defaultMsg;
    }

    public DefaultMsg delete(Long id) {
        DefaultMsg defaultMsg=new DefaultMsg();
        Integer count=mhallDao.delete(id);
        if (count==0){
            defaultMsg.setSuccess(0);
            defaultMsg.setError("失败");
        }
        return defaultMsg;    }
}
